package com.yf.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yf.domain.security.Role;
import com.yf.model.query.RoleQueryCriteria;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Set;

/**
 * @author chentianwei
 * @date 2023/6/25 11:01
 * @description 角色Dao
 */
@Mapper
public interface RoleMapper extends BaseMapper<Role> {

    Set<Role> findRolesByUserId(@Param("userId") Long userId);

    @Select("SELECT role.role_id as id FROM sys_role role, sys_roles_menus rm " +
            "WHERE role.role_id = rm.role_id AND rm.menu_id = #{menuId}")
    List<Role> findByMenuId(@Param("menuId") Long menuId);

    int countByDepts(@Param("deptIds") Set<Long> deptIds);

    List<Role> findAll(@Param("criteria") RoleQueryCriteria criteria);

    Role findByName(@Param("name") String name);

}
